#pragma once

#include <iostream>
#include <string>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
using namespace std;

const std::string gpipefile = "./fifo";
const mode_t gmode = 0600;
const size_t gsize = 1024;
const int gdefault = -1;
const int gread = O_RDONLY;
const int gwite = O_WRONLY;

int OpenPipe(int flag)
{
    //如果读端打开文件时，写端还没打开，读端对应的open就会阻塞，等待写端一起打开
    int fd = open(gpipefile.c_str(), flag);
    if (fd < 0)
    {
        cout << "open pipefile error" << endl;
    }
    return fd;
}

bool ClosePipeHeap(int fd)
{
    if (fd > 0)
    {
        close(fd);
        return true;
    }
    return false;
}